<?php
class ModelMessageOrder extends Model {
	
	public function addOrderBaseInfo($data=array()){
		$this->db->query("insert into ".DB_PREFIX."message_order set card_no='".$data['card_no']."',bussness_type_id='".$data['bussness_type_id']."',content='".$data['content']."',date_added=now()");
		return $this->db->getLastId();;
	}
	
	public function getOrderBaseInfoById($order_id){
		$query = $this->db->query("SELECT *  FROM `" . DB_PREFIX . "message_order` where order_id='".(int)$order_id."'");
		return $query->row;
	}
	
	public function getOrderBaseInfo($data=array()){
		$sql = "select * from ".DB_PREFIX."message_order mo left join  ".DB_PREFIX."config_bussness_type cbt on(cbt.bussness_type_id=mo.bussness_type_id) where 1=1 ";
		if(isset($data['card_no'])&&!empty($data['card_no'])){
			$sql .= " and mo.card_no='".$data['card_no']."' ";
		}else{
			$sql .= " and mo.card_no=001";
		}
		
		if(isset($data['filter_date_added'])&&!empty($data['filter_date_added'])){
			$sql .= " and DATE(mo.date_added)=DATE('".$data['filter_date_added']."')";
		}
		
		if(isset($data['bussness_type_id'])&&!empty($data['bussness_type_id'])){
			$sql .= " and mo.bussness_type_id='".$data['bussness_type_id']."' ";
		}
		$query = $this->db->query($sql);
		return $query->rows;
	}
	
	public function getAllBussnesss($data=array()){
		$sql = "SELECT * FROM `" . DB_PREFIX . "config_bussness_type`";
			
		$sort_data = array(
			'date_added'
		);	
			
		$query = $this->db->query($sql);
	
		return $query->rows;
	}
	
	public function getBussness($bussness_type_id){
		$sql = "SELECT * FROM `" . DB_PREFIX . "config_bussness_type` where bussness_type_id='".(int)$bussness_type_id."'";
		$query = $this->db->query($sql);
	
		return $query->row;
	}
	
	public function addOrderInfo($sender,$data=array()){
		$sql = "insert into ".DB_PREFIX."message_user_upload_info  set openid='".$sender."',upload_path='".$data['upload_path']."',file_name='".$data['file_name']."',date_added=now(),card_no='".$data['card_no']."',order_id='".(int)$data['order_id']."',bussness_type_id='".(int)$data['bussness_type_id']."',name='".$data['name']."'";
		$this->db->query($sql);
	}
	
	public function getOrderInfo($upload_info_id){
		$sql = "select * from ".DB_PREFIX."message_user_upload_info  where user_upload_info_id='".(int)$upload_info_id."'";
		return $this->db->query($sql)->row;
	}
	
	public function deleteOrderInfo($upload_info_id){
		$sql = "delete from ".DB_PREFIX."message_user_upload_info  where user_upload_info_id='".(int)$upload_info_id."'";
		$this->db->query($sql);
	}
	
	public function getOrderInfos($order_id){
		$sql = "select * from ".DB_PREFIX."message_user_upload_info  where order_id='".(int)$order_id."'";
		return $this->db->query($sql)->rows;
	}
}
?>